package cn.yunhe.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Juni
 * @date 2021/1/22
 * @Controller      将对象的创建交给IOC容器
 * @RequestMapping  设置请求地址及其他相关信息
 */
@Controller
public class MVCController {

    @RequestMapping(value = "/hello.do",method = RequestMethod.GET)
    public ModelAndView helloWorld(){
        //创建ModelAndView对象
        ModelAndView mv = new ModelAndView();
        //向ModelAndView中设置数据以及视图
        mv.addObject("data","hello SpringMVC");
        mv.setViewName("index.jsp");
        return mv;
    }

    @RequestMapping(value = "/helloRequest.do",method = RequestMethod.GET)
    public ModelAndView helloRequest(HttpServletRequest request, HttpServletResponse response){
        String flag = request.getParameter("flag");
        System.out.println(flag);
        //创建ModelAndView对象
        ModelAndView mv = new ModelAndView();
        //向ModelAndView中设置数据以及视图
        mv.addObject("data","hello SpringMVC");
        mv.setViewName("index.jsp");
        return mv;
    }
}
